<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        html, body {
            background-color: #f8f8f8;
        }
        .confirm_order,.continus_pay,.confirm_catch,.order_finish{
            bottom: 0px;
            position: absolute;
            background: white;
            width: 100%;
            padding: 8px 0;
            display: none;
        }
        .confirm_delivery{
            background: #e62442;
            color: white;
            overflow: hidden;
            margin-left: 10%;
            width: 80%;
            height: 34px;
            text-align: center;
            line-height: 34px;
            font-size: 16px;
            border-radius: 5px;
        }
        .order_finish .confirm_delivery{
            background: #FFBE22;
        }
        #header {
            height: 48px;
            line-height: 48px;
            background-color: #e62442;
            color: #fff;
            overflow: hidden;
        }
        #header .header_left {
            width: 20%;
            height: 100%;
            float: left;
            padding-left: 18px;
            box-sizing: border-box;
            display: -webkit-box;
            -webkit-box-align: center;
        }
        #header .header_left img {
            height: 20px;
            display: block;
        }
        #header .header_center {
            width: 60%;
            height: 100%;
            float: left;
            font-size: 17px;
            text-align: center;
        }
        #header .header_right {
            width: 20%;
            height: 100%;
            float: left;
            display: -webkit-box;
            -webkit-box-align: center;
            -webkit-box-pack: end;
            padding-right: 18px;
            box-sizing: border-box;
        }
        #header .header_right img {
            height: 20px;
            display: block;
        }
        .tap_active {
            /*background-color: rgba(0, 0, 0, 0.1);*/
        }
    </style>
</head>
<body>
   <header id="header">
        <div class="header_left" onclick="api.closeWin();" tapmode="tap_active">
            <img src="../image/back.png">
        </div>
        <div class="header_center">订单详情</div>
        <div class="header_right">
        </div>
    </header>
    <div class=" confirm_catch">
        <div class="confirm_delivery" tapmode onclick="fnToCatch();">确认骑手取货</div>
    </div>
    <div class=" confirm_order">
        <div class="confirm_delivery" tapmode onclick="fnToConfirm();">确认送达</div>
    </div>
    <div class=" order_finish">
        <div class="confirm_delivery">已送达</div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
    apiready = function(){
        $api.fixStatusBar(header);
        id = api.pageParam.id;
        status = api.pageParam.status;
        if(status == 0){
            // 未支付
            _h = api.frameHeight - 50 - $("#header").height();
        }else if(status == 4){
            _h = api.frameHeight - 50 - $("#header").height();
            $('.confirm_order').show();
        }else if(status == 2 || status == 3){
            _h = api.frameHeight - 50 - $("#header").height();
            $('.confirm_catch').show();
        }else if(status == 5 || status == 6){
            $(".order_finish").show();
            _h = api.frameHeight - 50 - $("#header").height();
        }
        api.openFrame({
            name: 'package_wait_confirm_and_finish_frame',
            url: 'package_wait_confirm_and_finish_frame.html',
            rect: {
                x: 0,
                y: $("#header").height(),
                w: 'auto',
                h: _h,
            },
            bounces: true,
            pageParam:{
                id:id,
                status:status
            }
        });
    };

    function fnToCatch () {
        user = $api.getStorage('user_data');
        api.ajax({
            url: rootPath+'/api/order/confirm_staff_catch_order',
            method: 'get',
            data: {
                values: { 
                    order_id: id,
                    uid:user.id,
                    token:user.token
                },
            }
        }, function(ret, err) {
            if (ret && ret.status == 201) {
                toast(ret.msg);
            } else if (ret && ret.status == 200){
                api.sendEvent({
                    name: 'orderChangeEvent',
                });
                toast('确认成功',300);
            }
        });
    };

    function fnHideConfirmButton () {
        $('.confirm_order').hide();
        api.setFrameAttr({
            name: 'package_wait_confirm_and_finish_frame',
            rect: {
                h: api.frameHeight
            },
        });
    };

    function fnToConfirm () {
        var jsfun = 'confirmDelivery();';
        api.execScript({
            frameName:'package_wait_confirm_and_finish_frame',
            script: jsfun
        });
    };

    function fnToPay () {
        var jsfun = 'continusPay();';
        api.execScript({
            frameName:'package_wait_confirm_and_finish_frame',
            script: jsfun
        });
    };


</script>
</html>